package com.example.jdbc_demo.mapper;

import com.example.jdbc_demo.entity.Student;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface StudentMapper {

    // 查询所有信息
    @Results(id = "studentResult", value = {
            @Result(column = "id", property = "id"),
            @Result(column = "name", property = "name"),
            @Result(column = "gender", property = "gender"),
            @Result(column = "nation", property = "nation"),
            @Result(column = "classID", property = "classID"),
            @Result(column = "score", property = "score")
    })
    @Select("select * from students")
    List<Student> getAll();


    // 根据id
    @ResultMap("studentResult")
    @Select("select * from students where id = #{id}")
    Student getStudentById(Integer id);


    //新增信息
    @Insert("insert into students(id,name,gender,nation,classID,score) values(#{id},#{name},#{gender},#{nation},#{classID},#{score})")
    int addStudent(Student student);

}
